package com.sys.ai.controller;

import com.sys.ai.domain.AiKnowledgeFile;
import com.sys.ai.service.IAiKnowledgeFileService;
import com.sys.common.annotation.Log;
import com.sys.common.core.controller.BaseController;
import com.sys.common.core.domain.AjaxResult;
import com.sys.common.core.page.TableDataInfo;
import com.sys.common.enums.BusinessType;
import com.sys.common.utils.poi.ExcelUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 知识文档Controller
 *
 * @author LGY
 * @date 2025-05-26
 */
@Tag(name = "知识文档")
@RestController
@RequestMapping("/ai/knowledgeFile")
public class AiKnowledgeFileController extends BaseController {
    @Autowired
    private IAiKnowledgeFileService aiKnowledgeFileService;

    /**
     * 查询知识文档列表
     */
    @PostMapping("/list")
    @Operation(summary = "查询知识文档分页列表")
    public TableDataInfo list(@RequestBody AiKnowledgeFile aiKnowledgeFile) {
        startPage(aiKnowledgeFile);
        List<AiKnowledgeFile> list = aiKnowledgeFileService.selectAiKnowledgeFileList(aiKnowledgeFile);
        return getDataTable(list);
    }

    /**
     * 导出知识文档列表
     */
    @Log(title = "知识文档", businessType = BusinessType.EXPORT)
    @Operation(summary = "导出知识文档")
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiKnowledgeFile aiKnowledgeFile) {
        List<AiKnowledgeFile> list = aiKnowledgeFileService.selectAiKnowledgeFileList(aiKnowledgeFile);
        ExcelUtil<AiKnowledgeFile> util = new ExcelUtil<AiKnowledgeFile>(AiKnowledgeFile.class);
        util.exportExcel(response, list, "知识文档数据");
    }

    /**
     * 获取知识文档详细信息
     */
    @Operation(summary = "查询知识文档详情")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(aiKnowledgeFileService.selectAiKnowledgeFileById(id));
    }

    /**
     * 新增知识文档
     */
    @Log(title = "知识文档", businessType = BusinessType.INSERT)
    @Operation(summary = "新增知识文档")
    @PostMapping("/save")
    public AjaxResult add(@RequestBody AiKnowledgeFile aiKnowledgeFile) {
        aiKnowledgeFileService.insertAiKnowledgeFile(aiKnowledgeFile);
        return success();
    }

    /**
     * 修改知识文档
     */
    @Log(title = "知识文档", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改知识文档")
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody AiKnowledgeFile aiKnowledgeFile) {
        aiKnowledgeFileService.updateAiKnowledgeFile(aiKnowledgeFile);
        return success();
    }

    /**
     * 删除知识文档
     */
    @Operation(summary = "删除知识文档")
    @Log(title = "知识文档", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        aiKnowledgeFileService.deleteAiKnowledgeFileByIds(ids);
        return success();
    }
}